package com.block.account.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Getter
public enum ActionTypeEnum {

    CZ("CZ", "充值")
    ,BD("BD", "补单")
    ,BUY("BUY", "购买")

    ;

    static List<String> changAmountTypeList = new ArrayList<>();
    static List<String> updateMainTypeList = new ArrayList<>();
    static {

        updateMainTypeList.add(CZ.getValue());
    }

    private String value;
    private String name;

    ActionTypeEnum(String value, String name){
        this.value = value;
        this.name = name;
    }

    public static BigDecimal getChangeAmount(String actionType, BigDecimal changeAmount){
        if (changAmountTypeList.contains(actionType)){
            return BigDecimal.ZERO.subtract(changeAmount);
        }
        return changeAmount;
    }

    public static boolean updateMainAction(String actionType){
        if (updateMainTypeList.contains(actionType)){
            return true;
        }
        return false;
    }

    public static ActionTypeEnum getEntityByType(String actionType){
        for (ActionTypeEnum typeEnum : values()) {
            if (StrUtil.equals(typeEnum.getValue(), actionType)){
                return typeEnum;
            }
        }
        return null;
    }




}
